<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>后台主界面</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" href='<?php echo $static_url; ?>common/css/admin.css' type="text/css" />
<link rel="stylesheet" href='<?php echo $static_url; ?>common/css/daily_record.css' type="text/css" />
<link rel="stylesheet" href='<?php echo $static_url; ?>common/css/treeview.css' type="text/css" />
<link rel="stylesheet" href='<?php echo $static_url; ?>common/css/news_list.css' type="text/css" />
<link rel="stylesheet" href='<?php echo $static_url; ?>common/css/news_add.css' type="text/css" />
<script src="<?php echo $static_url; ?>common/js/jquery-1.8.3.min.js" type="text/javascript"></script>
<script src="<?php echo $static_url; ?>common/js/common.js" type="text/javascript"></script>
<script src="<?php echo $static_url; ?>common/js/jquery.treeview.js" type="text/javascript"></script>
<script src="<?php echo $static_url; ?>ueditor/ueditor.config.js" type="text/javascript"></script>
<script src="<?php echo $static_url; ?>ueditor/ueditor.all.js" type="text/javascript"></script>
<script src="<?php echo $static_url; ?>common/js/My97DatePicker/WdatePicker.js" type="text/javascript"></script>
</head>
<body class="body_background">
	<div>
		<?php echo $header_nav; ?>
		<div class="common_container clearfix">
			<div class="crumbs">
				<span class="catalogue">文章管理</span>
				<a href="/www/admin/news/news_lists.php">文章列表</a> |
				<a href="/www/admin/news/news_add.php?category_id=<?php echo $category_id; ?>">添加文章</a> |
				<a href="/www/admin/news/empty_add.php?category_id=<?php echo $category_id; ?>">添加空白文章</a> |
				<a href="/www/admin/news/news_relative.php">手动推荐</a> |
				<a href="/www/admin/news/news_recover.php">回收站</a>
			</div>
			<div class="treeview_container" id="side_container">
				<div class="closeSidebar"><i title="点击隐藏左菜单" class="icon_close"></i></div>
				<h4>文章栏目</h4>
				<ul id="browser" class="filetree"></ul>
			</div>
			<div class="sidebar_container_hidden" style="margin-top:10px;margin-right:5px;"  >
				<div class="openSidebar"><i title="点击显示左菜单" class="icon_open"></i></div>
			</div>
			<div class="daily_record_main">
				<div class="news_add_container" id="main_container">
					<table class="record_tips"><tr><td class="colorstyle">添加文章</td></tr></table>
					<form action="/www/admin/news/do/do_add.php" method="post" enctype="multipart/form-data" onsubmit="return do_submit();">
					<table class="news_add_table">
						<tr>
							<td class="tleft w100">
								<span style="color:#f00;">*</span>
								<span class="fontWeight">栏目</span>
							</td>
							<td>
								<div id="category"></div>
							</td>
						</tr>
						<tr>
							<td class="tleft w100">
								<span style="color:#f00;">*</span>
								<span class="fontWeight">标题</span>
							</td>
							<td>
								<input type="text" class="ipt_wid415" name="title" id="title" />
								<span id="title_strlen"></span>
							</td>
						</tr>
						<tr>
							<td class="tleft w100">
								<span style="color:#f00;">*</span>
								<span class="fontWeight">来源</span>
							</td>
							<td>
								<input type="text" class="ipt_wid415" name="from_to" id="from_to" /><label>
								<input type="checkbox" id="is_reserved" name="is_reserved" />是否转载 </label>
							</td>	
						</tr>
						<tr>
							<td class="tleft w100">
								<span class="fontWeight">外部链接</span>
								
							</td>
							<td>
								<input type="text" class="ipt_wid415" name="url" id="url" />
							</td>
						</tr>
						<tr>
							<td class="tleft w100">
								<span style="color:#f00;">*</span>
								<span class="fontWeight">SEO关键字</span>
							</td>
							<td>
								<input type="text" class="ipt_wid415" name="seo_keyword" id="keyword" />
							</td>
						</tr>
						<tr>
							<td class="tleft w100">
								<span style="color:#f00;">*</span>
								<span class="fontWeight">SEO描述</span>
							</td>
							<td>
								<textarea style="width:800px;" name="seo_description" id="description"></textarea>
							</td>
						</tr>
						<tr id="images_tr" style="display:none">
							<td class="tleft w100">
								<span class="fontWeight ">缩略图</span>
							</td>
							<td>
								<input type="file" name="attach[images]" id="images"/>
								<span id="images_span"></span>
							</td>
						</tr>
						<tr id="periods_tr" style="display:none">
							<td></td>
							<td>
								<span>大话连体钞期数</span>
								<input type="text" class="ipt_wid220" name="periods" id="periods"/>
							</td>
						</tr>
						<tr id="jb_tr" style="display:none">
							<td></td>
							<td>
								<span>嘉宾姓名</span>
								<input type="text" class="ipt_wid220" name="jb_name" id="jb_name" />
								<span class=" ">嘉宾对话时间<span>
								<input type="text" class="ipt_wid220" name="time" id="time" onfocus="WdatePicker({dateFmt:'yyyy-M-d H:mm:ss'})" value=""/>
							</td>
						</tr>
						<tr id="bzmrt_tr" style="display:none">
							<td></td>
							<td>
								<span>版主姓名</span>
								<input type="text" class="ipt_wid220" name="mrt_name" id="mrt_name" />
							</td>
						</tr>
						<tr id="time_tr" style="display:none">
							<td></td>
							<td>
								<span class=" ">拍卖/活动开始时间</span>
								<input type="text" class="ipt_wid220" name="start_time" id="start_time" onfocus="WdatePicker({dateFmt:'yyyy-M-d H:mm:ss'})" value="" />	
								<span class=" ">拍卖/活动结束时间<span>
								<input type="text" class="ipt_wid220" name="end_time" id="end_time" onfocus="WdatePicker({dateFmt:'yyyy-M-d H:mm:ss'})" value="" />
							</td>
						</tr>
						<tr>
							<td class="tleft w100">
								<span class="news_require fontWeight">简介</span>
							</td>
							<td>
								<textarea style="width:800px;" name="intro" id="intro"></textarea>
							</td>
						</tr>
						<tr>
							<td class="tleft w100">
								<span class="news_require fontWeight">内容</span>
							</td>
							<td>
								<textarea name="content" id="content"></textarea>
								<input type="button" href="javascript:;" onclick="my_formatmatch()" value="格式化" style="height:25px;">
								<input type="button" href="javascript:;" onclick="my_clean_page()" value="去除分页" style="height:25px;">
							</td>
						</tr>
						<tr>
							<td>&nbsp;</td>
							<td>
								<span>初始点击数</span>
								<input style="height:25px;width:30px;" type="text" name="views" value=""/>&nbsp;&nbsp;
								<span class=" ">排序</span>
								<input style="height:25px;width:50px;" type="text" name="orders"/>&nbsp;&nbsp;
								<label> 
									<input type="checkbox" value="2" name="index_top" /> 首页置顶
								</label>&nbsp;&nbsp;
								<label> 
									<input type="checkbox" value="1" name="is_publish"/>是否定时发布
								</label> 
								<input type="text" name="publish_time" id="publish_time" onfocus="WdatePicker({dateFmt:'yyyy-M-d H:mm:ss'})" value=""/>
							</td>
						</tr>
						<tr id="mrt_tr" style="display:none">
							<td class="tleft w100">
								<span class="news_require fontWeight">
									版主名人堂<br />专访问答<br />(<a href="javascript:;" onclick="add_mrt_q_a()">新增一栏</a>)
								</span>
							</td>
							<td id="mrt_td"><hr />
								&nbsp;&nbsp;排序：<input type="text" name="mrt_orders[]" value="" style="height:25px;width:50px;"><br />
								&nbsp;&nbsp;Q：<textarea name="mrt_question[]" style="width:800px;"></textarea><br />
								&nbsp;&nbsp;A：<textarea name="mrt_answer[]" style="width:800px;"></textarea><hr />
							</td>
						</tr>
						<tr><td>&nbsp;</td><td>&nbsp;</td></tr>
						<tr>
							<td>&nbsp;</td>
							<td><input type="submit" value="提交" style="height:25px;"></td>
						</tr>
						<tr><td>&nbsp;</td><td>&nbsp;</td></tr>
					</table>
					</form>
				</div>
			</div>
		</div>
	</div>
<script>
$(function(){
	//加载栏目数据，并实例化
	var browser = $('#browser');
	browser.html('');
	$.ajax({
		type: "POST",
		url: "/admin/news/ajax/ajax_news_left_baner.php",
		dataType: 'html',
		data: {},
		beforeSend: function(){
			browser.html( '加载中...' );
		},
		success: function(data){
			browser.html( data ).treeview();
		}
	});
	
	//监测标题字数
	$('#title').keyup(function(){
		var category_id = $('#parent_id').val();//当前栏目id
		if( category_id == 35 ){//滚动广告栏目
			$('#title').removeAttr('maxlength');
			return '';
		}
		
		var len = $(this).val().length;
		if( len >= 0 && len < 22 ){
			var text = '还可输入'+(22-len)+'个字';
		}else{
			var text = '还可输入0个字';
		}
		$('#title_strlen').html('');
		$('#title_strlen').html(text);
	});
});

//实例化编辑器
var editor = new UE.ui.Editor();
editor.render("content");

//获取栏目
function category_start(i){<!-- i:id号 -->
	$.ajax({
		type: "POST",
		url: "/admin/news/category/ajax/ajax_start.php",
		dataType:'html',
		data: {"id":i,"news":2},
		success: function(data){
			$("#category").html("");
			html = data+'<input type="hidden" name="parent_id" id="parent_id" value="'+i+'"/>';
			$("#category").html(html);
			
			parent_id = i;
			$("#images_span").html('');
			
			//图像文本域
			var images_id_arr = new Array(31,36,39,40,41,46);//视频专区、嘉宾对话、名人榜、最新活动、图片轮播、版主名人堂
			if( in_array(parent_id, images_id_arr) ){
				html_arr = new Array(5);
				html_arr[31] = '（视频专区 最佳尺寸：210*170）';
				html_arr[36] = '（嘉宾对话 最佳尺寸：284*153）';
				html_arr[39] = '（名人榜 最佳尺寸：90*79）';
				html_arr[40] = '（最新活动 最佳尺寸：92*85）';
				html_arr[41] = '（图片轮播 最佳尺寸：296*220）';
				html_arr[46] = '（版主名人堂 最佳尺寸：150*200）';
				$("#images_span").html(html_arr[parent_id]);
				$('#images_tr').show();
			}else{
				$('#images_tr').hide();
			}
			//大话连体钞期数
			if( parent_id == 45 ){
				$('#periods_tr').show();
			}else{
				$('#periods_tr').hide();
			}
			//嘉宾姓名、对话时间
			if( parent_id == 36 ){
				$('#jb_tr').show();
			}else{
				$('#jb_tr').hide();
			}
			//版主名人堂
			if( parent_id == 46 ){
				$('#bzmrt_tr').show();
				$('#mrt_tr').show();
			}else{
				$('#bzmrt_tr').hide();
				$('#mrt_tr').hide();
			}
			//拍卖/活动 开始结束时间
			var time_id_arr = new Array(34,40);//拍卖、最新活动
			if( in_array(parent_id, time_id_arr) ){
				$('#time_tr').show();
			}else{
				$('#time_tr').hide();
			}
		}
	});
}

//栏目切换
$("select[id^='category_']").live("change", function(){
	var i = $(this).val();
	$.ajax({
		type: "POST",
		url: "/admin/news/category/ajax/ajax_get.php",
		dataType:'html',
		data: {"id":i,"news":2},
		success: function(data){
			$("#category").html("");
			$("#category").html(data);
			
			parent_id = $('#parent_id').val();
			$("#images_span").html('');
			
			//图像文本域
			var images_id_arr = new Array(31,36,39,40,41,46);//视频专区、嘉宾对话、名人榜、最新活动、图片轮播、版主名人堂
			if( in_array(parent_id, images_id_arr) ){
				html_arr = new Array(5);
				html_arr[31] = '（视频专区 最佳尺寸：210*170）';
				html_arr[36] = '（嘉宾对话 最佳尺寸：284*153）';
				html_arr[39] = '（名人榜 最佳尺寸：90*79）';
				html_arr[40] = '（最新活动 最佳尺寸：92*85）';
				html_arr[41] = '（图片轮播 最佳尺寸：296*220）';
				html_arr[46] = '（版主名人堂 最佳尺寸：150*200）';
				$("#images_span").html(html_arr[parent_id]);
				$('#images_tr').show();
			}else{
				$('#images_tr').hide();
			}
			//大话连体钞期数
			if( parent_id == 45 ){
				$('#periods_tr').show();
			}else{
				$('#periods_tr').hide();
			}
			//版主名人堂
			if( parent_id == 46 ){
				$('#bzmrt_tr').show();
				$('#mrt_tr').show();
			}else{
				$('#bzmrt_tr').hide();
				$('#mrt_tr').hide();
			}
			//嘉宾姓名、对话时间
			if( parent_id == 36 ){
				$('#jb_tr').show();
			}else{
				$('#jb_tr').hide();
			}
			//拍卖/活动 开始结束时间
			var time_id_arr = new Array(34,40);//拍卖、最新活动
			if( in_array(parent_id, time_id_arr) ){
				$('#time_tr').show();
			}else{
				$('#time_tr').hide();
			}
		}
	});
});

//初始化栏目
category_start(<?php echo $category_id;?>);

//提交检测
function do_submit(){
	var url = $('#url').val();
	if( $('#title').val() == '' ){
		alert('标题不能为空');
		$('#title').focus();
		return false;
	}else if( $('#from_to').val() == '' ){
		alert('来源不能为空');
		$('#from_to').focus();
		return false;
	}else if( $('#keyword').val() == '' ){
		alert('SEO关键词不能为空');
		$('#keyword').focus();
		return false;
	}else if( $('#description').val() == '' ){
		alert('SEO描述不能为空');
		$('#description').focus();
		return false;
	}else if( url == '' && editor.hasContents() == false ){
		alert('外部链接和内容两个不能同时为空');
		$('#url').focus();
		return false;
	}else{
		if( url != '' ){
			if( url.length < 7 || url.length > 255 || url.substr(0, 4) != 'http' ){
				alert("外部链接地址必须以http开头且字符长度不能小于7或大于256！");
				$('#url').focus();
				return false;
			}
		}
	}
	
	parent_id = $('#parent_id').val();
	start_time = $('#start_time').val();
	end_time = $('#end_time').val();
	jb_name = $('#jb_name').val();
	time = $('#time').val();
	intro = $('#intro').val();
	
	//大话连体钞
	if( parent_id == 45 ){
		if( $('#periods').val()=='' ){
			alert("请填写大话连体钞的期数");
			$('#periods').focus();
			return false;
		}else if( intro=='' ){
			alert("请填写大话连体钞的简介");
			$('#intro').focus();
			return false;
		}
	}
	//版主名人堂
	if( parent_id == 46 ){
		if( $('#images').val()=='' ){
			alert("请上传版主头像");
			return false;
		}else if( $('#mrt_name').val()=='' ){
			alert("请填写版主姓名");
			$('#mrt_name').focus();
			return false;
		}else if( intro=='' ){
			alert("请填写版主简介");
			$('#intro').focus();
			return false;
		}
	}
	//拍卖、嘉宾对话、名人榜、最新活动、图片轮播
	var id_arr = new Array(34,36,39,40,41);
	if( in_array(parent_id, id_arr) ){
		if( url == '' ){
			alert('当前栏目需要填写外部链接');
			$('#url').focus();
			return false;
		}
		if( parent_id != 34 && $('#images').val() == '' ){
			alert('当前栏目需要上传缩略图');
			return false;
		}
		if( parent_id == 34 ){
			if( start_time == '' || end_time == '' ){
				alert('请选择拍卖开始、结束时间');
				return false;
			}
		}else if( parent_id == 36 ){
			if( jb_name == '' || time == '' ){
				alert('请填写嘉宾名字并选择嘉宾对话开始时间');
				return false;
			}
		}else if( parent_id == 39 ){
			if( intro == '' ){
				alert('请填写名人简介');
				$('#intro').focus();
				return false;
			}
		}else if( parent_id == 40 ){
			if( editor.hasContents() == false || intro == '' || start_time == '' || end_time == '' ){
				alert('请填写活动简介、内容并选择开始、结束时间');
				return false;
			}
		}
	}
}

//查找元素是否在数组里
function in_array(needle, haystack) {
	if(typeof needle == 'string' || typeof needle == 'number') {
		for(var i in haystack) {
			if(haystack[i] == needle) {
				return true;
			}
		}
	}
	return false;
}

//新增名人堂一栏问答
function add_mrt_q_a(){
	mrt_html = '&nbsp;&nbsp;排序：<input type="text" name="mrt_orders[]" value="" style="height:25px;width:50px;"><br />&nbsp;&nbsp;Q：<textarea name="mrt_question[]" style="width:800px;"></textarea><br />&nbsp;&nbsp;A：<textarea name="mrt_answer[]" style="width:800px;"></textarea><hr />';
	$('#mrt_td').append( mrt_html );
}

//去除a标签
function myclean_a(html){
	var text;
	text = html.replace(/<a[^>].*?>/gi, '');
	text = text.replace(/<\/a>/gi, '');
	
	return text;
}

//纯文本分段落缩进
function my_formatmatch(){
	if( editor.hasContents() == true ){//有内容存在
		var html = editor.getPlainTxt();//获取带格式文本
		var text_array = html.split("\n");//转为数组
		var text_length = text_array.length - 1;//段落数
		
		var text = '';//初始化文本
		
		for(var i=0; i<text_length; i++){
			var new_text = text_array[i];
			
			//去除段前空格
			new_text = new_text.replace(/(^\s*)/g, "");
			
			//去a标签
			new_text = myclean_a( new_text );
			
			//过滤空白行
			if( new_text == '' ){
				continue;
			}
			
			//判断是否有img
			var img_html = new_text.match(/<img.*>$/gi);
			
			if( img_html != null ){//段落中间插入html
			
				text = text + '<p style="text-align:center">' + new_text + '</p><p style="text-indent: 2em;"><br /></p>';
			}else{
				text = text + '<p style="text-indent: 2em;">' + new_text + '</p><p style="text-indent: 2em;"><br /></p>';
			}
		}
		
		editor.setContent(text);
	}
}

//去除分页
function my_clean_page(){
	if( editor.hasContents() == true ){//有内容存在
		var html = editor.getContent();//获取文本
		
		var new_text = html.replace(/_ueditor_page_break_tag_/g, "");
		
		editor.setContent(new_text);
	}
}
</script>
</body>
</html>